package rlb;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import rlb.test.RobotTestBed;
import robocode.BattleResults;
import robocode.control.events.BattleCompletedEvent;

/**
 * See that FlankBot Can Beat Corners 1/4 the time.
 * 
 * @author Remy Baumgarten
 * 
 */
public class TestFlankBotVersusCorners extends RobotTestBed {

  /**
   * Specifies that Corners and FlankBot are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Corners,rlb.FlankBot";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * The actual test, which asserts that FlankBot has wins 1/4 of the rounds against corners.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    // Return the results in order of getRobotNames.
    BattleResults[] results = event.getIndexedResults();
    // Sanity check that results[1] is FlankBot (not strictly necessary, but illustrative).
    assertEquals("Check results[1]", results[1].getTeamLeaderName(), "rlb.FlankBot");
    System.out.println("FlankBot Beat Corners: " + results[1].getFirsts() + " out of "
        + getNumRounds() + "rounds");
    // Check to make sure wins 1/4 of rounds
    assertTrue("Check FlankBot winner", (results[1].getFirsts() >= (getNumRounds() / 4)));
  }
}
